//
//  BRScanCardSwift.swift
//  Chargebull
//
//  Created by 甘卫国 on 2024/4/10.
//

import Foundation
import StripeCardScan

@objc class BRScanCardSwift : NSObject {
    
    
    @MainActor @objc static let shared = BRScanCardSwift()
    private override init() {}
    
    @objc func presentSheet(_ vc:UIViewController ,succ:@escaping((String)->Void),fail:@escaping((String)->Void)) -> () {
        
        let cardScanSheet = CardScanSheet()
    
                cardScanSheet.present(from: vc) {  result in
                    switch result {
                        case .completed(let scannedCard):
                        /*
                         * The user scanned a card. The result of the scan are detailed
                         * in the `scannedCard` field of the result.
                         */
                        succ(scannedCard.pan)
                        print("scan success \(scannedCard.pan)")
                    case .canceled:
                        /*
                        * The scan was canceled by the user.
                        */
                        print("scan canceled")
                    case .failed(let error):
                         /*
                         * The scan failed. The displayable error is
                         * included in the `localizedDescription`.
                         */
                        fail(error.localizedDescription)
                        print("scan failed: \(error.localizedDescription)")
                    }
                }
    }
}
